<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>付款申请单</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<div class="Wrapper">
	<form id="capPayInfo_form">
		<div class="fieldset1 tabel_col clearFix">
			<div class="caption">
				<span class="title">基本信息</span>
			</div>
			<div class="fieldBox col_33">
				<div class="label">融资租赁合同号</div>
				<div class="field">
					<a href="javascript:toPrjDetail(${capPayInfoVO.prjId })" class="link">
						<span>${capPayInfoVO.contNo}</span>
					</a>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">支付表号</div>
				<div class="field">
					<a href="javascript:showPrjPrdPaySchDtl()" class="link">
						<span>${capPayInfoVO.paySchNo}</span>
					</a>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">承租人</div>
				<div class="field">
					<a href="javascript:showCstDtl(${capPayInfoVO.cstId})" class="link">
						<span>${capPayInfoVO.cstNm}</span>
					</a>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">所属事业部</div>
				<div class="field">
					<span>${capPayInfoVO.buOrgCdNm}</span>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">项目类型</div>
				<div class="field">
					<span>${capPayInfoVO.prjTypCdNm}</span>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">身份证号</div>
				<div class="field">
					<span>${mCertNo}</span>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">机构名称</div>
				<div class="field">
					<span>${fundRasInsNm}</span>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">手机号</div>
				<div class="field">
					<span>${mp}</span>
				</div>
			</div>
		</div>
		<div id="zgPayInfo" class="fieldset1 tabel_col clearFix">
			<div class="caption">
				<span class="title">放款信息</span>
			</div>
			<div class="fieldBox col_33">
				<div class="label">资方审批结果</div>
				<div class="field">
					<select name="payerStsCd" id="payerStsCd" data-value="" validate="{required:true}">
						<option value="2" selected="selected">通过</option>
						<option value="3" >不通过</option>
					</select>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">放款时间</div>
				<div class="field">
					<input name="thdPayDt" id="thdPayDt" type="text" class="ui-datepicker" data-value=""
						   validate="{required:false}" />
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">放款金额</div>
				<div class="field">
					<input name="thdPayAmt" id="thdPayAmt" class="ui-textbox" type="text" data-tofix="2" data-value=""
						   validate="{required:false,number:true}"/>
				</div>
			</div>
			<div class="fieldset1 clearFix">
				<div class="clearFix"></div>
				<div class="btnsBox">
					<span id="savePayInfo_Btn" class="sq-button sq-button-round" onclick="savePayInfo_Btn();">保存</span>
				</div>
			</div>
		</div>
		<div class="sqPanel">
			<div class="sqPanel_head inL">
				<span>资方还款计划</span>
				<%--<c:if test="${ pianflag != '101'}">
					<span class="btns"><span class="sq-button sq-button-round" onclick="downloadCstFileByUrl();">打包下载</span></span>
				</c:if>--%>
			</div>
			<div class="sqPanel_body">
				<div id="assetFileInfoGrid" class="sq-grid"></div>
			</div>
		</div>
		<input name="cstId" id="cstId" type="text" style="display: none;" value="${capPayInfoVO.cstId}">
		<input name="splId" id="splId" type="text" style="display: none;" value="${capPayInfoVO.splId}">
	</form>
</div>
<script type="text/javascript" src="<%=path %>/resource/lib/plugins/ajaxfileupload.js"></script>
<script>
var _capPayId = '${capPayId}';//付款信息ID
var _proIntId = '${proIntId}';//流程实例ID
var _taskId = '${taskId}';//任务节点ID
var _taskDefKey = '${taskDefKey}';//任务节点KEY
var _taskNm = '${taskNm}';//任务节点名称
var procNm = '${procNm}';//流程名称
var prjId = '${prjId}';//项目ID

var assetFileInfoGrid = null;//资方还款计划
var showZgPayInfo = '${showZgPayInfo}';
var payerStsCd = '${payerStsCd}';
var thdPayDt = '${thdPayDt}';
var thdPayAmt = '${thdPayAmt}';


    $(function () {
		$("#thdPayDt").ligerDateEditor({
			showTime: true,
			format: "yyyy-MM-dd hh:mm"
		});

		$("#capPayInfo_form").ligerForm();

		initZgPayInfo();

		//项目资料Grid
		assetFileInfoGrid = $("#assetFileInfoGrid").ligerGrid({
			<%--url: '<%=path%>/project/prjFileInfo/initPrjFileInfoList.do?cstMgrOrgCd=${cstMgrOrgCd}&prjId=${prjId}&prjTypCd=${prjTypCd}',--%>
			url: '<%=path%>/project/prjFileInfo/initPrjPayAssetFileList.do?capPayId=${capPayId}&prjId=${prjId}',
			method: 'get',
			columns: [
				{display: '资料名称', name: 'datNm',align: 'left', minWidth: 100, enabledSort: false,
					render:function(rowdata,rowindex,value){
						return '资方还款计划表';
					}},
				{display: '上传文件名称', name: 'fileNm', minWidth: 100, enabledSort: false,
					render:function(rowdata,rowindex,value){
						if(value){
							var h;
							h='<a href="javascript:uploadFileByUrl(';
							h+="'"+rowdata.filePath+"'";
							h+=",'"+rowdata.fileNm+"'";
							h+=')">'+rowdata.fileNm+'</a>'
							return h;
						}
					}
				},
				{display: '上传时间', name: 'crtTm',align: 'left', minWidth: 100, enabledSort: false,render:renderDate},
				{display: '状态', name: 'audStsCdNm', width: 100, enabledSort: false},
				{display: '上传', name: 'uploadNm', width: 80,align: 'left', enabledSort: false,
					render:function(rowdata,rowindex,value){
						var h='';
						//if(ctrlKey==1){
							<%--<sys:FlowFrmAth preTaskIds="${preTaskIds}" athCd="addPrjFile" pInstId="${pInstId}">--%>
							h+='<span class="sq-button sq-button-round fileupload-button">上传<input type="file" id="fileup_'+rowdata.cfgCd+'_'+rowdata.cfgDtlCd+'" multiple name="fileup_'+rowdata.cfgCd+'_'+rowdata.cfgDtlCd+'"' +
									' class="fileupload-input" onchange="onChangefile_multi(event,\''+rowdata.cfgCd+'\',\''+rowdata.cfgDtlCd+'\',\''+rowdata.orgCd+'\')"></span>';
							<%--</sys:FlowFrmAth>--%>
						//}
						return h;
					}
				},
			],
			root: 'rows',
			hideLoadButton : true,
			width: '100%',
			height: '100%',
			isScroll: false,
			rownumbers:true,  //显示序号
			checkbox: false,
			allowUnSelectRow:true,
			alternatingRow: false,
			frozen: false,
			usePager: false,
			onAfterShowData: function (){
				$('#assetFileInfoGrid').rowspan('datNm');
				$('#assetFileInfoGrid').rowspan('uploadNm');
			},
		});
    });

    
    //客户详情
    function showCstDtl(_cstId){
        Add_navTab("InsPlcCstBscInfo_"+_cstId, "客户信息", '<%=path%>/customer/cstbscinfo/toCustDetailPage.do?id='+_cstId, null);
    }
    //项目详情
    function toPrjDetail(_projectId){
    	if(!_projectId)return;
    	Add_navTab("prjDetail"+_projectId, "项目信息", '<%=path%>/project/prjbscinfo/toModifyPage.do?detailFlag=true&id='+_projectId);
    }
    // 支付表详情
    function showPrjPrdPaySchDtl(){
    	var editFlag = true;
    	var prjId = '${capPayInfoVO.prjId}';
    	var id = '${capPayInfoVO.paySchId}';
    	var prjPrdDtlId = '${capPayInfoVO.prjPrdDtlId}';
    	var prjPrdId = '${capPayInfoVO.prjPrdId}';
    	Add_navTab('tab_prj_quat_prps'+id,'查看支付表','<%=path%>/project/prjprdpayschm/toAddPage.do?prjId='+prjId+'&&id='+id+'&&prjPrdDtlId='+prjPrdDtlId+'&&prjPrdId='+prjPrdId+'&&detailFlag='+editFlag);
    }

	//格式化时间
	function renderDate(rowdata, index, value) {
		var dateStr = "";
		if (null != value) {
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
		}
		return dateStr;
	}

	function downFile(_url){
		//window.location.href=_url;
		window.open(_url);
	}

	function uploadFileByUrl(_url,_name){
		if(SQ.regs.img.test(_name)){
			//SQ.imgPreview(_url);
			//SQ.imgPreview(_url, true);
			window.__ImgSrc = _url;
			window.__ImgTit = _name;
			window.open('<%=path%>/project/prjbscinfo/imgWinOpen.do', '', 'location=yes, width=800, height=600');
		}else if(SQ.regs.img.test(_url)){
			window.__ImgSrc = _url;
			window.__ImgTit = _name;
			window.open('<%=path%>/project/prjbscinfo/imgWinOpen.do', '', 'location=yes, width=800, height=600');
		}else{
			window.open(_url);
		}
	}

	function onChangefile_multi(e,cfgCd,cfgDtlCd,orgCd) {
		var wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
		var filePath="prjPayAsset";
		var arrId = [];
		arrId[0] = e.target.id;
		$.ajaxFileUpload({
			url: '<%=path%>/system/sysulfilesrec/upload.do',
			secureuri: false,
			fileElementId: arrId,  //这里不在是以前的id了，要写成数组的形式！
			dataType: 'json',
			data: {filePath: filePath},
			success: function (msg) {
				if (msg.success == 1) {
					$.ajax({
						type: 'post',
						dataType: 'json',
						data: {'fileParams':JSON.stringify(msg.data),'capPayId':_capPayId,'prjId':prjId,'cfgCd':cfgCd,'cfgDtlCd':cfgDtlCd,'orgCd':orgCd},
						url: '<%=path%>/project/prjFileInfo/uploadPrjPayAssetFile.do',
						success: function (msg) {
							if (msg.success == 1) {
								assetFileInfoGrid.reload();
							}else{
								$.ligerDialog.SQalert({content: "资料上传超时", SQ_type: "error"});
							}
							$.ligerDialog.hide();
						}
					});
				} else {
					wait_dialog.close();
					$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
					// $.ligerDialog.SQalert({content: '文件上传失败，请重新上传', SQ_type: "error"});
				}
			}
		});
	};

    function initZgPayInfo() {
		if (null == showZgPayInfo || "true" != showZgPayInfo) {
			$("#zgPayInfo").hide();
			return;
		}

		var form = liger.get("capPayInfo_form");
		if (typeof (thdPayAmt) != "undefined" || null != thdPayAmt) {
			form.setData({
				thdPayAmt: thdPayAmt,
			});
		}

		if (typeof (thdPayDt) != "undefined" || null != thdPayDt) {
			form.setData({
				thdPayDt: thdPayDt,
			});
		}

		var payerStsCdCom = $("#payerStsCd").ligerGetComboBoxManager();
		if (typeof (payerStsCd) == "undefined" || null == payerStsCd || StringUtils.isEmpty(payerStsCd)) {
			payerStsCdCom.setValue("2");
			payerStsCdCom.setText("通过");
			liger.get("thdPayDt").setEnabled();
			liger.get("thdPayAmt").setEnabled();
		} else {
			if ("3" == payerStsCd) {
				payerStsCdCom.setValue("3");
				payerStsCdCom.setText("不通过");
				liger.get("thdPayDt").setDisabled(true);
				liger.get("thdPayAmt").setDisabled(true);
			} else {
				payerStsCdCom.setValue("2");
				payerStsCdCom.setText("通过");
				liger.get("thdPayDt").setEnabled();
				liger.get("thdPayAmt").setEnabled();
			}

		}

		$("#payerStsCd").ligerComboBox({
			onSelected: function (newValue)
			{
				if ("2" == newValue) {
					liger.get("thdPayDt").setEnabled();
					liger.get("thdPayAmt").setEnabled();
				} else {
					$("#thdPayAmt").val("");
					$("#thdPayDt").val("");
					liger.get("thdPayDt").setDisabled(true);
					liger.get("thdPayAmt").setDisabled(true);
				}
			}
		});

	}
    function savePayInfo_Btn() {
		var payerStsCd = $("#payerStsCd").val();
		var thdPayAmt = $("#thdPayAmt").val();
		var thdPayDt = $("#thdPayDt").val();

		if (!payerStsCd) {
			top.$.ligerDialog.SQalert({content: "审批结果不能为空!",SQ_type: "error"});
			return;
		}
		var params = {};
		params.thdPayDt = thdPayDt;
		if ("2" == payerStsCd) {
			if (!thdPayDt || null == thdPayDt) {
				top.$.ligerDialog.SQalert({content: "放款时间不能为空!",SQ_type: "error"});
				return;
			}
			if (!thdPayAmt || null == thdPayAmt || StringUtils.isEmpty(thdPayAmt)) {
				top.$.ligerDialog.SQalert({content: "放款金额不能为空!",SQ_type: "error"});
				return;
			}
			params.thdPayDt = thdPayDt+":00";
		}
		params.payerStsCd = payerStsCd;
		params.thdPayAmt = thdPayAmt;
		params.prjId = prjId;
		params.capPayId = _capPayId;

		var wait_dialog;
		$.ajax({
			type: 'post',
			dataType:'json',
			data:params,
			url: '<%=path%>/capPay/flow/addThdPayInfo.do',
			beforeSend: function () {
				wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
			},
			success:function(msg){
				wait_dialog.close();
				if(msg.success == 1){
					$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
				}else{
					top.$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				}
			}
		});

	}

</script>
</body>
</html>
